<template>
    <view>
        <custom><template #backText>我的商家账号</template></custom>
        <view class="cu-list menu">
            <nMenuItemContentAction v-for="(info, key) in list" :key="key" :top_title="info.name" :tap="()=>{changeLogin(info.user_id)}">
                <template #actionLeft>
                    <avatar avatar_size="lg" :avatar_url="info.logo"></avatar>
                </template>
                <template #content>
                    <view class="flex justify-between margin-left-16">
                        <text>{{info.name}}</text>
                        <text class="text-df text-gray">{{info.nickname}}</text>
                    </view>
                    <view class="margin-left-16">
                        <view class="text-sm text-gray margin-top-6 line-height-14em">
                            {{info.province_city_area_name}} {{info.address_remark}}
                        </view>
                    </view>
                </template>
            </nMenuItemContentAction>
        </view>
    </view>
</template>

<script>
    export default {
        data() {
            return {
                list: []
            }
        },
        onLoad(params) {
            this.pageInit();
        },
        methods: {
            pageInit(action) {
                this.$api.post(this, {
                    url: '/seller/apply/sellerListByApplyUser',
                    success: (Result) => {
                        if (this.$api.form.toast(this, Result)) return;
                        this.list = Result.result;
                    }
                });
            },
            changeLogin(user_id) {
                this.$api.post(this, {
                    loading: '切换商家账号中',
                    url: '/seller/apply/loginSellerByApplyUser',
                    data_append: {
                        seller_user_id: user_id
                    },
                    success: (Result) => {
                        if (this.$api.form.toast(this, Result)) return;
                        this.$store.commit('userChangeLoginSeller', Result.result);
                    }
                });
            }
        },
    }
</script>
